var echarts={
	//chartType 图标类型，bar直方图,pie饼图,line曲线图
	//data 传入的数据
	//areaDIV 图标展现的区域DOM
	
	"createChart": function(scope,chartType,chartName,chartData,DIV){//,xName,yName
		require([
					'echarts',
					'theme/sakura',
					'echarts/chart/bar',
					'echarts/chart/line',
					'echarts/chart/pie',
					'echarts/chart/chord',
					'echarts/chart/eventRiver',
					'echarts/chart/force',
					'echarts/chart/funnel',
					'echarts/chart/gauge',
					'echarts/chart/heatmap',
					'echarts/chart/k',
					'echarts/chart/map',
					'echarts/chart/radar',
					'echarts/chart/scatter',
					'echarts/chart/tree',
					'echarts/chart/treemap',
					'echarts/chart/venn',
					'echarts/chart/wordCloud'
		         ], 
		    function (ec,theme){

			myChart = ec.init(DIV,theme);
//			myChart = ec.init(DIV,'macarons');
		
			var option ;
			switch(chartType){
				case "bar":
					option=barOption(chartData,chartName);
					break;
				case "pie":
					option=pieOption(chartData,chartName);
					break;
				case "line":
					option=lineOption(chartData,chartName);
					break;
				case "wordCloud":
					option=wordCloudOption(chartData,chartName);
					break;
				default:
			}
			myChart.setOption(option);
			
			var ecConfig = require('echarts/config');
			myChart.on(ecConfig.EVENT.HOVER, tooltip_show);
			myChart.on(ecConfig.EVENT.MOUSEOUT, tooltip_hide);
			//隐藏提示框
			function tooltip_hide(){
				$("#ecTooltip").css("display","none");
			}
			//显示提示框
			function tooltip_show(param,p){
				var text = getParamText(param,p);
				$("#ecTooltip").html(text);
				var w = $("#ecTooltip").width();
				var h = $("#ecTooltip").height();
				var x = scope.x;
				var y = scope.y;
				var xleft = (x-w)<0?0:x-w;
				$("#ecTooltip").css("display","block").css("top",y-h-20).css("left",xleft);
				
			}
			//获取提示信息
			function getParamText(param,p){
				var dataIndex = param.dataIndex;
				var name = param.name;
				var value = param.value;
				var seriesName = param.seriesName;
				if (!seriesName) {
					seriesName = "";
				}
				var chartType = $(p.dom).attr("id").split('_')[0];
				var text = "";
				if ("pie" == chartType) {
					text = seriesName +'</br>'+name+'：'+value;
				}else if ("wordCloud" == chartType) {
					text = name+'：'+value;
				}else{
					text = name;
					var se = p.chart[chartType].series;
					for ( var i = 0; i < se.length; i++) {
						text += '</br>';
						var valName = se[i].name;
						var val = se[i].data[dataIndex];
						text += valName +'：'+val;
					}
				}
				return text;
			}//end
			
		});
	}
};